<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>HOME</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<!--<link rel="stylesheet" type="text/css" href="../css/app.css" />-->
		<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>

		<style type="text/css">
			.item {} .count {
				font-size: 14px;
			}
			.hastest {
				font-size: 16px;
			}
			.mui-collapse .parentNode {
				background-color: #f8f8fa;
				border-left: 4px solid #30a4ed;
			}
			.mui-table-view-cell.mui-active {
				/*border-left: 4px solid #51d1c2;*/
			}
			.mui-table-view {
				background-color: #f8f8fa;
				color: #fff;
			}
			.mui-table-view-chevron .mui-table-view-cell {
				/*margin-left: -4px;*/
				
				height: 80px;
				background-color: #f8f8fa;
				color: #51d1c2;
				border-left: 4px solid #51d1c2;
			}
			.mui-table-view-chevron .mui-table-view-cell p {
				color: #51d1c2;
			}
			.mui-table-view-cell:after {
				background-color: #e2e2e4;
				right: 15px;
				/*background-color: #c8c7cc;*/
				/*right: 15px;*/
			}
			.mui-table-view-cell.mui-collapse .mui-table-view .mui-table-view-cell:after {
				background-color: #e2e2e4;
				left: 11px;
				right: 66px;
			}
			.mui-table-view-chevron .mui-table-view-cell:first-child:before {
				position: absolute;
				top: 0;
				right: 66px;
				left: 15px;
				height: 1px;
				content: '';
				-webkit-transform: scaleY(.5);
				transform: scaleY(.5);
				background-color: #e2e2e4;
			}
			.orders {
				background-color: #3E9FEC;
			}
			.order {
				height: 90px;
			}
			.ordername {
				color: #fff;
			}
			.orderdetail {
				margin: -11px -15px;
				padding: 10px 10px;
				height: 40px;
				background-color: #fefefe;
				color: #ccc;
			}
			.leftnav {
				padding-top: 10px;
			}
		</style>

	</head>

	<body>
		<!--<div class="mui-content">-->
		<ul class="mui-table-view" id="list">

		</ul>
		<!--</div>-->
	</body>
	<script type="text/html" id="listTem">
		{{each}}
		<li class="mui-table-view-cell orders">
			<a class="order" data-sn="{{$value.sn}}" onclick="openDetail({{$value.id}})">
				<span class="mui-pull-left">
						<p class="ordername">订单名称</p>
						<h4 style="font-size: 16px;">{{$value.title}}</h4>
				</span>
				<span class="mui-pull-right leftnav"><img src="../image/edit03.png" style="height: 30px;"/></span>
			</a>
			<div class="orderdetail">
				<p>
					<span class="mui-col-xs-5 mui-pull-left">日期：{{$getLocalTime($value.createdtime)}}</span>
					<span class="mui-col-xs-4 mui-pull-left">金额：{{$value.amount}}元</span>
					<span class="mui-col-xs-3 mui-pull-left">状态：{{if $value.status=="paid"}}已付款{{/if}}{{if $value.status=="created"}}未付款{{/if}}{{if $value.status=="cancelled"}}已取消{{/if}}</span>
				</p>
			</div>
		</li>
		{{/each}}
	</script>
	<script src="../script/app.js" type="text/javascript" charset="utf-8"></script>
	<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		template.helper('$getLocalTime', function(nS) {
			var d = new Date(parseInt(nS) * 1000);
			var s = '';
			s += d.getFullYear() + '.';
			s += (d.getMonth() + 1) + '.';
			s += d.getDate();
//			s += d.getHours() + ':';
//			s += d.getMinutes();
			return s;
		});

		function success(ret) {
			var html = template('listTem', ret.data);
			document.getElementById("list").innerHTML = html;
		}
		function openDetail(id){
			var data =  {
				id:id
			};
			api.openWin({
				name: 'order-detail',
				url: 'order-detail.html',
				pageParam: data
			});
		}
		apiready = function() {
			var key = localStorage.getItem('key');
			var data = {
				key:key
			};
			var url = MYAPP.webroot+"/api/index.php/Home/Order/myOrder";
			api.ajax({
				url: url,
				method: 'post',
				timeout: 30,
				dataType: 'json',
				data: {
					values: data
				},
				returnAll: false
			}, function(ret, err) {
				if (ret) {
					if(ret.code==200){
						success(ret);
					}else{
						api.toast({
							msg:ret.error
						});
					}
					
				} else {
					api.toast({
						msg: '错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode,
						location: 'middle',
						duration: 1000
					});
				}
			});
		}
	</script>

</html>